package com.company;
import java.util.Scanner;

public class CodeInputAndScan {
    static Scanner scanner=new Scanner(System.in);//用于键盘输入源程序
    static String origincode=new String();//用于模拟缓冲区的字符串
    static int point=0;//用point模拟缓冲区的指针

    public static void main(String[] args) {
        inputOriginCode();//调用该方法输入源代码
        while(point<origincode.length()){//调用子程序读出输入的源程序
            System.out.print(CodeInputAndScan.getChar(origincode));
        }
    }

    public static void inputOriginCode(){
        System.out.println("请输入源程序,若输入完毕请换行输入exit结束输入:");
        while(scanner.hasNextLine()){
            String str=scanner.nextLine();
            if(str.equals("exit"))break;
            origincode=origincode+str;
        }
        scanner.close();//输入完毕,关闭输入流
    }

    public static char getChar(String origincode){//读入一个字符的子程序
        char ch='#';
        if(point<=origincode.length()-1){
            ch=origincode.charAt(point);
            point++;//字符读出,缓冲区指针移动
        }
        return ch;
    }
}
